package com.zhiyun.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zhiyun.domain.CourseComment;
import com.zhiyun.mapper.CourseCommentMapper;
import com.zhiyun.service.CourseCommentService;
import com.zhiyun.util.Db;
import com.zhiyun.vo.Result;

import java.util.List;

/**
 * @author zc
 * @Date 2025/4/29 下午4:00
 */
public class CourseCommentServiceImpl implements CourseCommentService {
    CourseCommentMapper courseCommentMapper = Db.getMapper(CourseCommentMapper.class);
    @Override
    public Result findCourseCommentByIdAndPage(int courseId, int pageNum) {
        PageHelper.startPage(pageNum, 5);
        List<CourseComment> list = courseCommentMapper.findByCourseId(courseId);
        PageInfo<CourseComment> pageInfo = new PageInfo<>(list);
        return Result.ok(pageInfo);
    }

    @Override
    public Result addCourseComment(CourseComment courseComment) {
        int insert = courseCommentMapper.insert(courseComment);
        if (insert > 0) {
            return Result.okMsg("评价成功");
        }else {
            return Result.fail("评价失败");
        }
    }
}
